@file:Suppress("UNCHECKED_CAST")

package com.mycontract.suitepro.extend

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.mycontract.suitepro.base.BaseActivity
import com.mycontract.suitepro.contract.*
import com.mycontract.suitepro.enums.PageTagEnum

inline fun <reified T> AppCompatActivity.startContractSuiteToContractSuiteNextContractSuiteActivity(params: HashMap<String, String> = HashMap()) {
    try {
        val intent = Intent(this, T::class.java)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

inline fun <reified T> AppCompatActivity.startContractSuiteToContractSuiteNextContractSuiteActivityContractSuiteAndContractSuiteFinish(
    params: HashMap<String, String> = HashMap()
) {
    try {
        val intent = Intent(this, T::class.java)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
        finish()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

inline fun <reified T> AppCompatActivity.startContractSuiteToContractSuiteNextContractSuiteActivityContractSuiteForContractSuiteSingleContractSuiteTop(
    params: HashMap<String, String> = HashMap()
) {
    try {
        val intent = Intent(this, T::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
        finish()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

fun Fragment.startContractSuiteToContractSuiteNextContractSuiteFromContractSuitePage(
    pageTag: PageTagEnum,
    params: HashMap<String, String> = HashMap()
) {
    (requireContext() as BaseActivity).startContractSuiteToContractSuiteNextContractSuiteFromContractSuitePage(
        pageTag = pageTag,
        params = params
    )
}

fun AppCompatActivity.startContractSuiteToContractSuiteNextContractSuiteFromContractSuitePage(
    pageTag: PageTagEnum,
    params: HashMap<String, String> = HashMap()
) {

}

/////////////
/** 去签约列表页 */
fun AppCompatActivity.startContractSuiteToContractSuiteContractContractSuiteIndexContractSuitePage(params: HashMap<String, String> = HashMap()) {
    startContractSuiteToContractSuiteNextContractSuiteActivityContractSuiteForContractSuiteSingleContractSuiteTop<ContractIndexActivity>(
        params
    )
}

/** 去签约页 */
fun AppCompatActivity.startContractSuiteToContractSuiteContractContractSuiteSignContractSuitePage(params: HashMap<String, String> = HashMap()) {
    startContractSuiteToContractSuiteNextContractSuiteActivity<ContractSignWebActivity>(
        params
    )
}

/** 去签约-数据声明页 */
fun AppCompatActivity.startContractSuiteToContractSuiteContractContractSuiteDataContractSuiteSafetyContractSuitePage(params: HashMap<String, String> = HashMap()) {
    startContractSuiteToContractSuiteNextContractSuiteActivity<ContractDataSafetyWebActivity>(
        params
    )
}


/** 去签约-上传数据页 */
fun AppCompatActivity.startContractSuiteToContractSuiteContractContractSuiteDataContractSuiteUploadContractSuitePage(params: HashMap<String, String> = HashMap()) {
    startContractSuiteToContractSuiteNextContractSuiteActivity<ContractDataUploadActivity>(
        params
    )
}

/** 签约成功页 */
fun AppCompatActivity.startContractSuiteToContractSuiteContractContractSuiteSignContractSuiteSuccessContractSuitePage(params: HashMap<String, String> = HashMap()) {
    startContractSuiteToContractSuiteNextContractSuiteActivityContractSuiteAndContractSuiteFinish<ContractSignSuccessActivity>(
        params
    )
}